package sort;

import java.util.Random;

/**
 * @author:李雄
 * @ClassName:SelectionSort
 * @Description: 选择排序
 * @createTime:2022-11-13 20:57
 */
public class SelectionSort {
    public static void main(String[] args) {
        int arr[] = new int[100];
        for (int i = 0; i < 100; i++) {
            arr[i] = new Random().nextInt(0 + 10);
        }
        mySelectionSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    private static void mySelectionSort(int[] arr) {

        int i = 0;
        int index = 0;
        int j;
        for (; i < arr.length; i++) {
            int temp = arr[i];
            for (j = i; j < arr.length; j++) {
                if (temp > arr[j]) {
                    temp = arr[j];
                    index = j;
                }
            }
            arr[index] = arr[i];
            arr[i] = temp;
        }
    }
}
